package com.shanshan.system.controller;

import com.shanshan.system.entity.Notice;
import com.shanshan.system.service.NoticeService;
import com.shanshan.system.vo.NoticeVo;
import com.shanshan.system.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author keluoyisi
 * @program: shanshan
 * @description:
 * @date 2023-02-08 21:56:50
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    /**
     * 通知列表
     * @param currentPage 当前页面
     * @param pageSize    页面大小
     * @return {@link Result}
     */
    @RequestMapping("/noticeList")
    public Result noticeList(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody NoticeVo noticeVo){
        System.out.println(noticeVo);
        return noticeService.queryAllNotice(currentPage,pageSize,noticeVo);
    }

    /**
     * 删除通过id
     * @param id id
     * @return {@link Result}
     */
    @RequestMapping("/deleteById")
    public Result deleteById(int id){
        return noticeService.deleteById(id);
    }

    /**
     * 更新通知
     * @param notice 请注意
     * @return {@link Result}
     */
    @RequestMapping("/updateNotice")

    public Result updateNotice(@RequestBody Notice notice){
        return noticeService.updateNotice(notice);
    }

    /**
     * 添加通知
     * @param notice 请注意
     * @return {@link Result}
     */
    @RequestMapping("/addNotice")
    public Result addNotice(@RequestBody Notice notice){
        return noticeService.addNotice(notice);
    }

    @GetMapping("/list")
    public Result list(){
        return noticeService.findAll();
    }
}
